Skip to content

Conversation

@ghost
Copy link

@ghost ghost commented Oct 16, 2018

Edit Nov 11 5pm

Thank you all for the feedback. I'm working on Keanu's fork for now: https://github.com/keanulee/lit-element/

The docs site is staged here: https://polymer-lit-element-staging.appspot.com/


docs: Main docs folder. gh-pages will build the docs site from Jekyll source in here. Only the source files (listed below) need review :)

These folders/files need review:

What is the other stuff & why is it here??

Other stuff is build output required for the docs site to run; doesn't need to be reviewed. E.g.

  • docs/_site: Generated Jekyll output
  • docs/build: Build output - needed for StackBlitz to run in gh-pages
  • docs/_includes/projects: Duplicate of content in docs/projects because Jekyll can't find them if they're not here, and my src/* code can't find them if they are here. I need a better way of serving these files :)

@ghost ghost requested a review from sorvell as a code owner October 16, 2018 07:40
@ghost
Copy link
Author

ghost commented Oct 16, 2018

Demo: https://katejeffreys-projects.github.io/lit-element/

super();
this.myProp='there';
this.setTimeout(() => {
this.myProp='world';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spaces around = ?

<p>Learn more:</p>

<ul>
<li><a href="/try/">Try lit-element</a> without intalling anything.</li>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo : intalling -> installing

```js
render({}){
return html`
<button on-click="${(e) => this._clickHandler(e)}"></button>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is @click now

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some information on what this is would be useful, as there is special handing in lit-html for that

<button on-click="${(e) => this._clickHandler(e)}"></button>
`;
}
_clickHander(e){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space before {


</article>


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

an excessive amount of newlines here

this.project={};
}
render(){
var filenames=[];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't use var today :-)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I would add spaces around assignment as well as between () and { - that seems like common style

}
render(){
var filenames=[];
if(this.project.files) var filenames=Object.keys(this.project.files);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as well as after if which isn't a function

this.shadowRoot.getElementById('toggle').disabled = false;
}
async embedProject(project){
var slot = this.shadowRoot.getElementById("slot");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const?

this.loadProject();
}

loadProject() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

async loadProject and then use of async/await would make the below easier to read

}

loadProject() {
if (this.folder == 'undefined') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the 's ?

<li>
<a href="/try/">Try lit-element</a>


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is up with all these newlines?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jekyll/Liquid does it. Will fix. :)

@@ -0,0 +1,132 @@
import {LitElement, html} from '@polymer/lit-element';
Copy link
Contributor

@43081j 43081j Oct 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.bak, is this file meant to be here?

}

}
;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This semicolon is probably unnecessary


}

;
Copy link

@elarb elarb Oct 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This semicolon is probably unnecessary as well


embedProject(project, options) {
var embedIn = this.shadowRoot.getElementById('stackblitz');
const vm = sdk.embedProject(embedIn, project, options);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vm doesn't seem to be used

Create custom elements that update on property changes. lit-element creates DOM once, then re-renders only the stuff that changed - making DOM updates lightning-fast.

```js
static get properties(){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space between () and {

@43081j
Copy link
Contributor

43081j commented Oct 16, 2018

@katejeffreys you may want to mention what part of this people should be reviewing.

unless im mistaken, a lot of this is build output so shouldn't be code reviewed, rather the sources should. seems those are in docs/*.


## React to property changes

Create custom elements that update on property changes. lit-element creates DOM once, then re-renders only the stuff that changed - making DOM updates lightning-fast.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the DOM?

<p><strong>Create fast, lightweight, reusable web components that work in any web page:</strong></p>

<div class="language-js highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">class</span> <span class="nx">MyElement</span> <span class="kd">extends</span> <span class="nx">LitElement</span><span class="p">{</span>
<span class="c1">// implemnt MyElement</span>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: implemnt -> implement


<a id="expressions"></a>

## Use simple JavaScript expressions for loops and conditionals
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why simple? You can use advanced as well :-)

Use well-known JavaScript expressions for loops and conditionals


## Use simple JavaScript expressions for loops and conditionals

Handling conditionals and loops in your lit-element templates is easy. No special annotations, just plain JavaScript expressions:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/plain/regular?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think I'll just remove "plain"

<ul>
${myArray.map(i => html`<li>${i}</li>`)}
</ul>
${myBool?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add space before ? as well as before : - that makes it must easier to read and spot what you are doing

Use JavaScript expressions to add event listeners in plain HTML:

```js
render({}){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think render takes arguments anymore

return html`
<style>
:host, #staticsample {
min-height:50vh;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space after :

<div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>import { LitElement, html } from '@polymer/lit-element';

/**
* Anti-pattern. Avoid manipulating DOM.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

manually

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you mean.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lit-html manipulates the DOM, so the anti-pattern is that people manually manipulate it

@43081j
Copy link
Contributor

43081j commented Oct 17, 2018

I opened #270 related to the formatting. If we figure that out we can run it again on the docs JS too.

Until then though it looks like it'll mangle a lot of your html templates and what not 😢

<div class="prevnext">
<div class="next">
{%- if include.nexturl -%}
<a href="{{include.nexturl}}">Next: {{include.nexttitle}} &gt;&gt;</a>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something wonky is going on here with escaping. see image:
image

Copy link
Contributor

@e111077 e111077 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops disregard my review. I meant to leave that as a comment


```html
<head>
<script type="module" src="node_modules/package-name/existing-element.js"></script>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest importing by name with inline script instead and let the tools will handle the resolution:

<script type=module>
import 'package-name/existing-element.js';
</script>

This is what we did for PolymerElement demos (e.g. https://github.com/PolymerElements/iron-list/blob/master/demo/index.html#L20).

@keanulee
Copy link
Contributor

docs/projects/ removed; docs/_includes/projects/ is the single source for examples now.

async loadProject() {
const folder = this.folder;
if (folder) {
const response = await fetch(`${folder}/manifest.json`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this have problems with multiple clicks? Can you disable the button and add visual feedback that the click was registered?

<ul>
${this.myArray.map(i => html`<li>${i}</li>`)}
</ul>
${this.myBool?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest moving the ? and : to the begging of each result for better readability like so:

      ${this.myBool
         ? html`<p>Render some HTML if myBool is true</p>`
         : html`<p>Render some other HTML if myBool is false</p>`
       }

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this, will edit samples accordingly if I get time.

`;
}
firstUpdated(changedProperties){
console.log(changedProperties);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you doing console.log(changedProperties) here? It seems unnecessary.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometimes I like to do console output to illustrate things to the reader. It's just a sample and they can ignore it if they want.

`;
}
firstUpdated(changedProperties){
console.log(changedProperties);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% on this but I believe you're supposed to call super.firstUpdated(changedProperties) when you use firstUpdated

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't see anything to suggest this in the code or readme.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, my bad

}
changeMe(prop){
var rand = Math.floor(Math.random()*100);
prop=='prop1'?this.prop1=rand:this.prop2=rand;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should either be an if statement or can be simplified into:

Suggested change
prop=='prop1'?this.prop1=rand:this.prop2=rand;
this[prop] = rand;

<!-- Style this text -->
<p class="${this.myBool?'red':'blue'}">style me</p>
<button @click="${(event) => this.clickHandler(event)}">Click</button>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems redundant to wrap a method in an arrow function. Instead you can just bind this.clickHandler:

Suggested change
<button @click="${(event) => this.clickHandler(event)}">Click</button>
<button @click="${this.clickHandler.bind(this)}">Click</button>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the recent "event context" addition, this should just be ${this.clickHandler} to avoid having to call .bind() each render. See #244

<p>${this.message}</p>
<ul>${this.myArray.map(i => html`<li>${i}</li>`)}</ul>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of i here could be potentially confusing as i usually stands for index. Maybe it or text would be better here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, will edit

@lit lit deleted a comment from 43081j Nov 12, 2018
@lit lit deleted a comment from keanulee Nov 12, 2018
@ghost
Copy link
Author

ghost commented Nov 12, 2018

Closing this PR because it will be better to raise from Keanu's fork.

@ghost ghost closed this Nov 12, 2018
@ghost ghost deleted the docs branch December 4, 2018 03:28
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.